cost function for multi-class classification